﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace TulingMember.Database.Migrations.Migrations
{
    public partial class adddepartmenttable : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<DateTime>(
                name: "Birthday",
                table: "cts_Customer",
                type: "datetime2",
                nullable: false,
                defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));

            migrationBuilder.AddColumn<string>(
                name: "MedicalCardNo",
                table: "cts_Customer",
                type: "nvarchar(max)",
                nullable: true);

            migrationBuilder.AddColumn<int>(
                name: "Sex",
                table: "cts_Customer",
                type: "int",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.CreateTable(
                name: "cts_Department",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false, comment: "Id主键"),
                    Name = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ParentId = table.Column<long>(type: "bigint", nullable: true),
                    Sort = table.Column<int>(type: "int", nullable: false, comment: "排序"),
                    CreatedTime = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true, comment: "创建时间"),
                    UpdatedTime = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true, comment: "更新时间"),
                    CreatedUserId = table.Column<long>(type: "bigint", nullable: false, comment: "创建者Id"),
                    CreatedUserName = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true, comment: "创建者名称"),
                    UpdatedUserId = table.Column<long>(type: "bigint", nullable: true, comment: "修改者Id"),
                    UpdatedUserName = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true, comment: "修改者名称"),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, comment: "软删除标记"),
                    TenantId = table.Column<long>(type: "bigint", nullable: true, comment: "租户id")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_cts_Department", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "DepartmentCustomer",
                columns: table => new
                {
                    CustomerId = table.Column<long>(type: "bigint", nullable: false),
                    DepartmentId = table.Column<long>(type: "bigint", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DepartmentCustomer", x => new { x.DepartmentId, x.CustomerId });
                    table.ForeignKey(
                        name: "FK_DepartmentCustomer_cts_Customer_CustomerId",
                        column: x => x.CustomerId,
                        principalTable: "cts_Customer",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_DepartmentCustomer_cts_Department_DepartmentId",
                        column: x => x.DepartmentId,
                        principalTable: "cts_Department",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.UpdateData(
                table: "Role",
                keyColumn: "Id",
                keyValue: 142307070910554L,
                column: "CreatedTime",
                value: new DateTimeOffset(new DateTime(2023, 6, 10, 18, 22, 58, 367, DateTimeKind.Unspecified).AddTicks(6571), new TimeSpan(0, 8, 0, 0, 0)));

            migrationBuilder.UpdateData(
                table: "Security",
                keyColumn: "Id",
                keyValue: 142307070910555L,
                column: "CreatedTime",
                value: new DateTimeOffset(new DateTime(2023, 6, 10, 18, 22, 58, 367, DateTimeKind.Unspecified).AddTicks(7358), new TimeSpan(0, 8, 0, 0, 0)));

            migrationBuilder.UpdateData(
                table: "Security",
                keyColumn: "Id",
                keyValue: 142307070910556L,
                column: "CreatedTime",
                value: new DateTimeOffset(new DateTime(2023, 6, 10, 18, 22, 58, 367, DateTimeKind.Unspecified).AddTicks(7364), new TimeSpan(0, 8, 0, 0, 0)));

            migrationBuilder.UpdateData(
                table: "Security",
                keyColumn: "Id",
                keyValue: 142307070910557L,
                column: "CreatedTime",
                value: new DateTimeOffset(new DateTime(2023, 6, 10, 18, 22, 58, 367, DateTimeKind.Unspecified).AddTicks(7366), new TimeSpan(0, 8, 0, 0, 0)));

            migrationBuilder.UpdateData(
                table: "User",
                keyColumn: "Id",
                keyValue: 142307070910551L,
                column: "CreatedTime",
                value: new DateTimeOffset(new DateTime(2023, 6, 10, 18, 22, 58, 368, DateTimeKind.Unspecified).AddTicks(3248), new TimeSpan(0, 8, 0, 0, 0)));

            migrationBuilder.CreateIndex(
                name: "IX_DepartmentCustomer_CustomerId",
                table: "DepartmentCustomer",
                column: "CustomerId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "DepartmentCustomer");

            migrationBuilder.DropTable(
                name: "cts_Department");

            migrationBuilder.DropColumn(
                name: "Birthday",
                table: "cts_Customer");

            migrationBuilder.DropColumn(
                name: "MedicalCardNo",
                table: "cts_Customer");

            migrationBuilder.DropColumn(
                name: "Sex",
                table: "cts_Customer");

            migrationBuilder.UpdateData(
                table: "Role",
                keyColumn: "Id",
                keyValue: 142307070910554L,
                column: "CreatedTime",
                value: new DateTimeOffset(new DateTime(2023, 6, 8, 20, 47, 22, 576, DateTimeKind.Unspecified).AddTicks(5869), new TimeSpan(0, 8, 0, 0, 0)));

            migrationBuilder.UpdateData(
                table: "Security",
                keyColumn: "Id",
                keyValue: 142307070910555L,
                column: "CreatedTime",
                value: new DateTimeOffset(new DateTime(2023, 6, 8, 20, 47, 22, 576, DateTimeKind.Unspecified).AddTicks(6982), new TimeSpan(0, 8, 0, 0, 0)));

            migrationBuilder.UpdateData(
                table: "Security",
                keyColumn: "Id",
                keyValue: 142307070910556L,
                column: "CreatedTime",
                value: new DateTimeOffset(new DateTime(2023, 6, 8, 20, 47, 22, 576, DateTimeKind.Unspecified).AddTicks(6992), new TimeSpan(0, 8, 0, 0, 0)));

            migrationBuilder.UpdateData(
                table: "Security",
                keyColumn: "Id",
                keyValue: 142307070910557L,
                column: "CreatedTime",
                value: new DateTimeOffset(new DateTime(2023, 6, 8, 20, 47, 22, 576, DateTimeKind.Unspecified).AddTicks(6995), new TimeSpan(0, 8, 0, 0, 0)));

            migrationBuilder.UpdateData(
                table: "User",
                keyColumn: "Id",
                keyValue: 142307070910551L,
                column: "CreatedTime",
                value: new DateTimeOffset(new DateTime(2023, 6, 8, 20, 47, 22, 577, DateTimeKind.Unspecified).AddTicks(3092), new TimeSpan(0, 8, 0, 0, 0)));
        }
    }
}
